程序 入口点 是任何 Go 应用程序必须的“启动”序列,由 package main 和 func main() 代码块定义。按步骤编写这些指令的方式被称为 命令式编程。
1. 核心定义
- 程序 func 关键字用于声明一个函数(一个命名的代码块)。
func main()是程序执行的通用起始行。
2. Go 语法规则
Go 依赖特定的标点符号来理解你的意图: 引号 用于文本, 括号 用于传递数据,以及 花括号 用于逻辑分组。 fmt 包提供了将输出打印到控制台所需的工具。
提示:打字很重要
请自己输入代码!打字错误会导致语法错误,学会纠正它们是每位开发者必备的技能。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
Where does a Go program start its execution?
Inside the import "fmt" statement.
In the func main() function within package main.
At the first line of the fmt package.
Inside the package entry block.
✅ Correct!
Correct! Every executable Go program must have a main package and a main function.❌ Incorrect
Go specifically looks for func main() to begin the execution sequence.QUESTION 2
What primary functionality does the
fmt package provide?Memory management and garbage collection.
Mathematical algorithms and randomization.
Formatting and printing text to the console.
Declaring the entry point of the application.
✅ Correct!
Exactly. Short for 'format', it handles input and output.❌ Incorrect
The fmt package is used for communicating with the external console through formatting.QUESTION 3
Which punctuation is used in Go to group blocks of code together?
Parentheses ( )
Curly Braces { }
Square Brackets [ ]
Double Quotes " "
✅ Correct!
Braces are used to define the scope and body of functions and control structures.❌ Incorrect
Braces {} define code blocks, while parentheses () are generally for data input/functions.QUESTION 4
What is the term for writing down explicit, step-by-step instructions for a computer?
Declarative Programming
Imperative Programming
Functional Formatting
Sequential Scripting
✅ Correct!
Imperative programming is the practice of dictating exact execution paths.❌ Incorrect
The source context defines this specific practice as imperative programming.QUESTION 5
[Short Answer] Which is greater, an "apple" or a "banana"?
Apple
Banana
✅ Correct!
"banana" is greater because it comes later in alphabetical order/Unicode value.❌ Incorrect
In lexicographical comparison, 'b' has a higher value than 'a'.Mission Control: The First Ignition
Entry Point Logic and Syntax Validation
You are at your mission control console (the Go Playground). You need to modify the default greeting and ensure your structural logic (the 'One True Brace Style') is correct to avoid a syntax error.
Q
[Short Answer] Where must opening braces { be placed to avoid syntax errors? (Required Output: 15 words)
Solution:
The opening brace must be placed on the same line as the statement it begins.
The opening brace must be placed on the same line as the statement it begins.
Q
Experiment: playground.go. How do you modify the provided code to greet yourself by name?
Solution:
Change the text between the double quotes in the fmt.Println function to your own name, for example: fmt.Println("Hello, Commander [Name]").
Change the text between the double quotes in the fmt.Println function to your own name, for example: fmt.Println("Hello, Commander [Name]").